package main

import (
	"fmt"
	rs "github.com/gomodule/redigo/redis"
	"gostep/databases/redis"
	"strconv"
)



type Comment struct {
	PostId int
	UserId int
	Content string
	CreateAt string
}

var BlogKeyPrefix ="blog:"
var BlogCountKey ="blogs:count"
func InsertPost(name string)error{
	// 1.判断是否存在post
	// 2.获取post
	count,err:=redis.Count(BlogCountKey)
	if err == rs.ErrNil{
		fmt.Println(err)
		err:=redis.Set(BlogCountKey,"0")
		if err!=nil{
			return err
		}
	}else if err!=nil && err!=rs.ErrNil{
		return err
	}

	err=redis.Incr(BlogCountKey)
	if err!=nil{
		return err
	}

	err=redis.HSet(BlogKeyPrefix+strconv.Itoa(count+1),"Name",name)
	if err!=nil{
		return err
	}

	return nil
}

